package controllers

import (
	"tms-server/gin/models"
	"tms-server/utils"

	"github.com/gin-gonic/gin"
)

type UserControllers struct{}

var UserContrl = new(UserControllers)

func (*UserControllers) Query(c *gin.Context) (res interface{}, e Error) {
	start := utils.Max(0, c.GetInt("start"))
	limit := 20
	users, err := models.FindUsers(start, limit)
	if err != nil {
		return nil, GenError(err)
	}
	data := make([]map[string]interface{}, 0)
	for _, user := range users {
		info := user.GenResponse()
		data = append(data, info)
	}
	res = data
	return
}

func (*UserControllers) Get(c *gin.Context) (res interface{}, e Error) {
	id := c.GetInt64("playerId")
	user, err := models.FindUserByID(id)
	if err != nil {
		return nil, GenError(err)
	}
	res = user.GenResponse()
	return
}

func (*UserControllers) Update(c *gin.Context) (res interface{}, e Error) {
	res = "user.update"
	return
}

func (*UserControllers) Delete(c *gin.Context) (res interface{}, e Error) {
	res = "user.update"
	return
}
